Background Runs
BindAI v0.1 provides a REST API for submitting automation runs for background execution. Background runs allow a client to submit work without keeping the original HTTP request open until the automation completes. The API provides two endpoints:Background Run Architecture
The v0.1 architecture is:AutomationRun implementation.
Authentication
Background-run endpoints are protected by the BindAI API authentication layer. Clients must provide:Submit a Background Run
A new background run is submitted with:automation_id identifies an automation definition that has already been configured in the BindAI API application.
The input field is optional and can contain application-specific data.
The current API stores the supplied input on the resulting AutomationRun.
It should not be assumed that the current automation worker automatically passes this input into AutomationDefinition.run(). Applications should treat the stored run input and the automation definition’s execution input as separate concerns until explicit input propagation is implemented.
Example Request
Using cURL:AutomationWorker.
Submission Response
A successful submission returns HTTP202 Accepted.
The response contains information about the created run.
A response can look like:
id is the run identifier used to query the run later.
HTTP 202 Accepted
Background execution uses HTTP202 Accepted because the request submits work for execution rather than waiting for the automation to finish.
The request lifecycle is:
202 Accepted as successful completion of the automation.
It means that the run has been accepted for background execution.
Get Run Status
A submitted run can be inspected with:Run Response
A run response contains fields corresponding to theAutomationRun model:
status rather than assuming a particular state immediately after submission.
Run Lifecycle
TheAutomationWorker creates an AutomationRun before submitting background execution.
The run is then updated as execution progresses.
Conceptually:
null while a run is still in progress.
Polling
A client can poll the run endpoint until execution reaches a terminal state. For example:Python Client Example
A Python application can submit a background run using an HTTP client. For example:JavaScript Example
A JavaScript application can submit a run usingfetch:
Run Input
The submission request supports an optionalinput value:
AutomationRun.
The meaning of the input is application-specific.
An important v0.1 detail is that the current AutomationWorker stores this input on the run but invokes the automation definition using:
input field should currently be understood as run metadata/state, not as an automatic argument passed to the automation definition.
Applications that require input-driven execution should explicitly connect their input data to the automation’s execution logic.
Automation Definition
Theautomation_id identifies an automation definition configured in the BindAI application.
Conceptually:
Definition Version
Background runs include the automation definition version. This allows a run to identify the version of the automation definition associated with it. For example:Run State
The run contains execution metadata such as:started_at or completed_at value.
Successful Runs
A completed run can contain an output value. Conceptually:Failed Runs
A failed run can contain an error description. Conceptually:Run Not Found
If a requested run does not exist in the available worker state or history, the API returns a not-found response. For example:Background Worker
The v0.1 API uses anAutomationWorker for background execution.
The worker uses an in-process ThreadPoolExecutor.
Its responsibilities include:
- creating
AutomationRuninstances - persisting run state
- submitting background work
- updating run lifecycle state
- recording completed or failed runs in history
Worker Submission
The worker exposes two related background-submission operations. The simple form returns aFuture:
submit_with_run() persists the newly created AutomationRun before background execution starts.
This allows the API to return the run information without waiting for the automation to complete.
Synchronous Worker Execution
AutomationWorker also supports synchronous execution:
Process-Local Execution
The most important v0.1 limitation is that the worker is process-local. The worker exists inside the application process:What Process-Local Means
If the application process stops, background work running inside that process can be interrupted. For example:No Distributed Queue
The v0.1 background-run implementation does not provide a distributed message queue. It does not automatically coordinate:Horizontal Scaling
Running multiple API instances does not automatically create one shared background execution system. For example:Durable Execution
The v0.1 worker should not be considered a durable distributed job system. Durable execution generally requires persistent state and coordination outside the application process. A future architecture can look like:Background Runs vs Streaming
Background runs and streaming serve different purposes. Background runs:Background Runs vs Synchronous Execution
Synchronous execution keeps the request open while execution completes.Background Runs and Automation Scheduling
Background runs are different from scheduled automation. A background run is explicitly submitted through the API:Background Runs and Observability
Background executions can produce runtime events through BindAI’s event system. Relevant events can include:- agent events
- workflow events
- node events
- model events
- tool events
- memory events
EventRecorder for recording events emitted through an execution context’s event bus.
This can support:
- debugging
- execution inspection
- custom logging
- future metrics integrations
- future tracing integrations
Error Handling
Background execution can fail for the same reasons as other BindAI executions. Potential failures include:- model provider errors
- tool errors
- workflow errors
- connection failures
- external-service failures
- invalid automation configuration
- application errors
AutomationRun.
Clients should inspect the run’s status and error fields rather than assuming that a successfully submitted run will always complete successfully.
Retries
The currentAutomationWorker does not automatically retry failed runs.
Retry behavior, where supported by higher-level automation or workflow configuration, should be treated separately from the worker’s basic execution lifecycle.
Clients should not blindly resubmit failed background runs.
For example:
Idempotency
Background operations should be designed with idempotency in mind. This is especially important when an automation performs:- API writes
- notifications
- emails
- database updates
- deployment operations
- ticket creation
- external workflow changes
Security
Background runs can execute tools and connections with access to external services. Protect the run endpoints accordingly. Recommended practices include:- use strong API keys
- use HTTPS
- protect external credentials
- limit connection permissions
- validate automation inputs
- avoid exposing secrets through run input or output
- avoid logging sensitive run data
- restrict access to state-changing automations
Input and Output Data
Run input and output can contain application data. For example:- personal information
- credentials
- internal identifiers
- confidential business data
- external-service responses
AutomationDefinition.run().
Production Considerations
Before using background runs in production, consider:- process lifetime
- deployment restarts
- container restarts
- worker capacity
- execution duration
- external-service reliability
- retry behavior
- idempotency
- monitoring
- run-state persistence
- failure recovery
Docker
Background runs work inside the same BindAI API container when using the v0.1 Docker deployment. Conceptually:Docker Compose
Docker Compose can run the BindAI API locally:API Health vs Run Health
The/health endpoint indicates basic API service availability:
Testing
The API package includes tests for the background-run endpoints. Run the API tests with:- run submission
- run lookup
- authentication
- missing runs
- successful execution
- failed execution
- worker submission
- synchronous worker execution
- run state transitions
- history recording
Current v0.1 Scope
BindAI v0.1 provides:- background run submission
- run identifiers
- run status lookup
- run input storage
- run output
- run errors
- creation timestamps
- start timestamps
- completion timestamps
- in-process automation workers
- thread-pool background execution
- API-key authentication
Current Limitations
The v0.1 background-run system does not provide:- distributed queues
- durable distributed workers
- cross-instance worker coordination
- Kubernetes-native job execution
- built-in worker autoscaling
- managed cloud workers
- guaranteed execution after process failure
- a distributed run-state database
- automatic worker retries
- dead-letter queues
Future Distributed Execution
A future BindAI architecture can introduce a persistent queue:- durable job submission
- worker coordination
- multiple worker processes
- multiple worker machines
- retry recovery
- queue monitoring
- horizontal scaling
- better process-failure recovery
Recommended Usage
For v0.1, background runs are appropriate when:- the work can execute inside the API process
- losing in-process work during a process restart is acceptable
- a lightweight background execution model is sufficient
- the deployment does not require coordinated workers
- the application can handle the current persistence limitations
Example End-to-End Flow
A complete background-run flow can look like:Summary
BindAI v0.1 provides background automation execution through:AutomationWorker backed by a thread pool.
The worker creates and tracks AutomationRun instances, executes automation definitions in background threads, persists state, and records completed or failed runs in history.
The current API’s input value is stored on the run. It is not automatically passed as an argument to AutomationDefinition.run() by the current worker implementation.
The most important deployment limitation is:
